﻿using CanDoo.Admin.Core.Contracts;
using CanDoo.Core.Context;
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.OAuth;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace CanDoo.Oil.WebApi.Areas.Api.Filters
{
    /// <summary>
    /// 你好 API 
    /// </summary>
    [OverrideAuthentication]
    [RoutePrefix("api/Hello")]
    //[Authorize]
    [HostAuthentication(OAuthDefaults.AuthenticationType)]
    public class HelloController : ApiController
    {
        public IOperator Operator { get;private set; }

        public HelloController(IOperator @operator)
        {
            Operator = @operator;
        }
        
        /// <summary>
        /// 访问我获取申请access_token方法
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        public IEnumerable<string> Get()
        {
            var data = new string[]{
                "this.User.Identity.IsAuthenticated=" + this.User.Identity.IsAuthenticated,
                "this.User.Identity.Name=" + this.User.Identity.Name
            };
            return data;
        }

        /// <summary>
        /// 返回用户信息
        /// </summary>
        public IOperator Post()
        {
            return Operator;
        }
    }
}
